#include <iostream>
#include <stdlib.h>

#include <nemesis.Logger.h>

#include <nemesis.dbms.Connection.h>

#include <nemesis.dbos.AutoObject.h>

#include <dbos_demo.defines.h>

#include <dbos_demo.oodb.Table01.h>

#include <dbos_demo.phase.Instanciate.h>

using namespace std;
using namespace nemesis;
using namespace dbos_demo;

void phase::Instanciate::do_comment () const
   throw ()
{
   cout << "Carga un registro de ReadWrite varias veces para verificar que solo se recarga cuando la cuenta" << endl;
   cout << "de utilizacion de la instancia value cero" << endl << endl;
}

void phase::Instanciate::do_apply (dbms::Connection& connection)
   throw (RuntimeException, dbms::DatabaseException)
{
   using namespace nemesis::dbms;

   Guard guard (connection);

   const int id (MaxKey01 / 2);
   string msg;
   
   {
      dbos::AutoObject <oodb::Table01> table01_1, table01_2;

      table01_1 = oodb::Table01::instanciate (connection, id);
      
      LOGINFORMATION (
         string msg (table01_1->asString ());
         msg += " | Primer uso";      
         Logger::information (msg, FILE_LOCATION);
      );
      
      table01_2 = oodb::Table01::instanciate (connection, id);
      
      LOGINFORMATION (
         string msg (table01_2->asString ());
         msg += " | Segundo uso";      
         Logger::information (msg, FILE_LOCATION);
      );
      
   }

    dbos::AutoObject <oodb::Table01> table01;

    table01 = oodb::Table01::instanciate (connection, id);
    
    LOGINFORMATION (
      string msg (table01->asString ());
      msg += " | Tercer uso";      
      Logger::information (msg, FILE_LOCATION);
   );
}

 

